﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Collections;
using System.Data ;
using System.Windows.Forms;
using h = functionService.shorts;
using da = functionService.DATECOD;
using fr = HK.FiscalRegistrar.FiscalRegistrar;
using vv = functionService.serfun_city7;
using tg = functionService.tagWork ;

namespace enterData
{
    enum modeEnter { work, set}
    enum tag { cod, name, cop, lev, fo }
    enum buttons { cod123, lev, cod, name, cop, fo }
    enum whatButton { folder, buttonActiv, buttonEmpty, noButton }

    class Class_enterData
    {

        public functionService.prm_city q;
        public modeEnter current_modeEnter;
        public System.Collections.Stack stk;
        public int iFirstStep;
        public ToolStripButton bFirstStep;
       // string tn = q.tk((int)ETALON.param.name_listtov_57); string sch = q.tk((int)ETALON.param.name_schema_58);
        string tn, sch;
        int currentCOP;
        //int currentLev, currentCOP, currentCod; string currentParentTag;

        public Class_enterData()
        {
            iFirstStep = 0; currentCOP = 0;
            stk = new System.Collections.Stack();
            bFirstStep = new ToolStripButton();

            q = new functionService.prm_city();
            string s = q.tk((int)ETALON.param.server_1);
            q.con.co(s);
            current_modeEnter = modeEnter.work;
            tn = q.tk((int)ETALON.param.name_listtov_57); sch = q.tk((int)ETALON.param.name_schema_58);
        }
        public void readStake()
        {
            int ic = stk.Count;  object[] o = new object[ic];  o = stk.ToArray();  //h.m(o.Length);
        }
        public void changeMode(ListView lv1, ListView lv2,  ToolStripStatusLabel tsl, Button[] ab)
        {
            string s_work = "work", s_set = "set";
            ArrayList a = new ArrayList(); a.Add(s_work); a.Add(s_set);
            city7.lists.set.FormSETt f = new city7.lists.set.FormSETt(s_work, s_set);
            f.ShowDialog(); int ii = 0;
            bool b = false;
            if (f.IsOk)
            {
                /*ii = Convert.ToInt32(l.sCod);
                current_modeEnter = (modeEnter)ii; */
                if (f.valueSelect  == s_work)
                {
                    current_modeEnter = modeEnter.work; tsl.Text = "WORK"; lv1.Visible = true; lv2.Visible = true;
                }
                else if (f.valueSelect == s_set)
                {
                    current_modeEnter = modeEnter.set;  tsl.Text = "SET"; b=true;  lv1.Visible = false; lv2.Visible = false;
                }

                viewButton(ab, b);
            }
        }
        public void viewButton(Button[] ab0, bool trueFalse)
        {
            //string st; 
            whatButton w;
            for (int j = 0; j < ab0.Length; j++)
            {
                //st = ab0[j].Tag.ToString();
                w = clickButton(ab0[j].Tag.ToString());
                if (trueFalse == false)
                {
                    if (w == whatButton.buttonEmpty || w == whatButton.noButton)
                    {
                        ab0[j].Visible = trueFalse;
                    }
                }
                else { ab0[j].Visible = trueFalse; }
            }
        }
        public void moveUp(Button[] ab0, ListView l1, ListView l2)
        {
            //readStake();
            if (stk.Count == 1)
            {
              stk.Clear();
              loadFolderObjName(bFirstStep, ab0);
            }
            else if (stk.Count > 1)
            {
                object  ob = stk.Pop();
                string ButtonTag = (string)stk.Pop();
                //h.m(ButtonTag);
                loadFolderObjName_afterButton01234
                    (ButtonTag, ab0,  l1,  l2);
            }
        }


        public void loadFolderObjName(ToolStripButton bb,
            Button[] ab0)
        {
            int codF = tg.readTAGi(bb.Tag, (int)tag.cod);
            //string tn = q.tk((int)ETALON.param.name_listtov_57); string sch = q.tk((int)ETALON.param.name_schema_58);
            DataTable t12 =
               q.selectAny
               (
               h.a("call `city`.`select_treea_folder`(", codF, ",'", sch, "', '", tn, "');")
               );
            
                for (int j = 0; j < ab0.Length; j++)
                {
                    ab0[j].Text = "-";
                    ab0[j].ImageIndex = 3;
                    ab0[j].Tag = h.az(0, 0, 0, "-", 0, 2);
                    if (current_modeEnter == modeEnter.work)
                    {
                        ab0[j].Visible = false;
                    }
                    else
                    { ab0[j].Visible = true ; }
                }
            

            

            int i = 0;
            foreach (DataRow r in t12.Rows)
            {
                ab0[i].Tag = h.az(r[(int)buttons.cod123],
                    r[(int)buttons.lev],
                    r[(int)buttons.cod],
                    r[(int)buttons.name],
                    r[(int)buttons.cop],
                    r[(int)buttons.fo]);

                ab0[i].Text = r[3].ToString();
                ab0[i].ImageIndex = Convert.ToInt32(r[(int)buttons.fo]);
                ab0[i].Visible = true;
                i++;
            }
           
         
        }
        public void loadF()
        {
 
        }
        public void loadFO(int codFld, Button[] ab0)
        {
            DataTable t12 = 
                            q.selectAny
                            (
                            h.a
                                (
                                "call `city`.`select_treea_folder`(", codFld
                                , ",'", sch, "', '", tn, "');"
                                )
                            );
            //h.m(t12);
            setEpty01234(ab0);
            int i = 0;
            foreach (DataRow r in t12.Rows)
            {
                ab0[i].Tag = h.az
                    (
                    r[(int)buttons.cod123],
                    r[(int)buttons.lev],
                    r[(int)buttons.cod],
                    r[(int)buttons.name],
                    r[(int)buttons.cop],
                    r[(int)buttons.fo]
                    );
                ab0[i].Text = r[3].ToString();
                ab0[i].ImageIndex =
                    Convert.ToInt32(r[(int)buttons.fo]);
                i++;
            }

        }

        public void loadFolderObjName_afterButton01234
            (string strButtonTag, Button[] ab0, ListView l1, ListView l2)
        {
           // h.m(strButtonTag);
            if (tg.readTAGi(strButtonTag, 5) == 0
                && tg.readTAGi(strButtonTag, 2) != 0)
            {

                stk.Push(strButtonTag);
                int codFld = tg.readTAGi(strButtonTag, (int)buttons.cod); currentCOP = codFld;
                DataTable t12 =
                 q.selectAny
                 (
                 h.a
                     (
                     "call `city`.`select_treea_folder`(", codFld
                     , ",'", sch ,"', '", tn ,"');"
                     )
                 );
                setEpty01234(ab0);

                int i = 0;
                foreach (DataRow r in t12.Rows)
                {
                    ab0[i].Tag = h.az
                        (
                        r[(int)buttons.cod123],
                        r[(int)buttons.lev],
                        r[(int)buttons.cod],
                        r[(int)buttons.name],
                        r[(int)buttons.cop],
                        r[(int)buttons.fo]
                        );
                    ab0[i].Text = r[3].ToString();
                    ab0[i].ImageIndex =
                        Convert.ToInt32(r[(int)buttons.fo]); 
                    ab0[i].Visible = true;
                    i++;
                }
            }
            else 
            {
                selectNoFolder(strButtonTag,l1,l2);
            }
        }
        public void selectNoFolder(string strButtonTag, ListView l1, ListView l2)
        {
            if (tg.readTAGi(strButtonTag, 2) == 0)
            {
                //h.m(h.a("pro   ",strButtonTag));
            }
            else 
            { 
               // h.m(h.a("obj   ", strButtonTag));

                Add_ProdKol_ed2(strButtonTag, l1, l2);
            }
        }

       /*
        public void loadFolderObjName
            (Button bb, Button[] ab0)
        {
            //-------------**************----------------???????????
            Button rb = (Button)stk.Peek();
           
            int lev = tg.readTAGi(bb.Tag, (int)buttons.lev);
            if (lev == 1)
            {
                stk.Clear(); stk.Push(bb);
            }
            else if (lev > 1)
            {
               
            }

            if (
                tg.readTAGi(bb.Tag, (int)buttons.lev) >
                tg.readTAGi(rb.Tag, (int)buttons.lev)
               )
            { stk.Push(bb); }
            
           
            currentCOP = currentCod;
            currentParentTag = bb.Tag.ToString();
            currentCod = tg.readTAGi(bb.Tag, (int)buttons.cod);
            
            DataTable t12 =
               q.selectAny
               (
               h.a(
               "call `city`.`select_treea_folder`(", currentCod
               , ",'city', 'listtov21');")
               );

            ab0[0].Text = "...";
            ab0[0].ImageIndex = 4;
            ab0[0].Tag = h.az(0, 0, currentCod, "...", currentCOP, 0);

            for (int j = 1; j < ab0.Length; j++)
            {
                ab0[j].Text = "-";
                ab0[j].ImageIndex = 3;
                ab0[j].Tag = h.az(0, 0, currentCod, "...", currentCOP, 0);
            }
            int i = 1;
            foreach (DataRow r in t12.Rows)
            {
                ab0[i].Tag = h.az(r[(int)buttons.cod123],
                    r[(int)buttons.lev],
                    r[(int)buttons.cod],
                    r[(int)buttons.name],
                    r[(int)buttons.cop],
                    r[(int)buttons.fo]);

                ab0[i].Text = r[3].ToString();
                ab0[i].ImageIndex = Convert.ToInt32(r[(int)buttons.fo]);
                i++;
            }
            

        }
        */

        public void loadFolderObjNameUp(int codFolder,
            Button[] ab0)
        {

            Button bap = (Button)stk.Pop();
            //codFolder
            DataTable t12 =
               q.selectAny
               (
               h.a(
               "call `city`.`select_treea_folder`(", tg.readTAG(bap.Tag, (int)buttons.cod)
               , ",'",sch ,"', '",tn,"');")
               );
             

            object selectCop = ""; int i = 1;
            if (tg.readTAGi(bap.Tag, (int)buttons.lev) > 0)
            {
                selectCop = q.selectScalar
                    (
                    h.a(
                    "select cop from city.",tn,"_folders where cod = ", codFolder
                    , " and lev = ", tg.readTAG(bap.Tag, (int)buttons.lev)
                    , ";")
                    );

                ab0[0].Text = "...";
                ab0[0].ImageIndex = 4;
                ab0[0].Tag = h.az(0, 0, codFolder, "...", selectCop, 0);

                for (int j = 1; j < ab0.Length; j++)
                {
                    ab0[j].Text = "-";
                    ab0[j].ImageIndex = 3;
                    ab0[j].Tag = h.az(0, 0, codFolder, "...", selectCop, 0);
                }

            }
            else 
            { 
                selectCop = 888; 
                for (int j = 0; j < ab0.Length; j++)
                {
                    ab0[j].Text = "-";
                    ab0[j].ImageIndex = 3;
                    ab0[j].Tag = h.az(0, 0, codFolder, "...", selectCop, 0);
                }

                i = 0;
            }
  


            
            foreach (DataRow r in t12.Rows)
            {
                ab0[i].Tag = h.az(r[(int)buttons.cod123],
                    r[(int)buttons.lev],
                    r[(int)buttons.cod],
                    r[(int)buttons.name],
                    r[(int)buttons.cop],
                    r[(int)buttons.fo]);

                ab0[i].Text = r[3].ToString();
                ab0[i].ImageIndex = Convert.ToInt32(r[(int)buttons.fo]);
                i++;
            }


        }


        

       
      

        #region button lev1...2
        public void click_Button_any(Button sb, Button[] ab, ListView l1, ListView l2)
        {
            if (current_modeEnter == modeEnter.set)
            {
                selectSetMode(sb.Tag.ToString(), ab);
            }
            else if (current_modeEnter == modeEnter.work )
            {
               // readStek();
             //  vv.kol = 1;
                if (vv.kolSet_bool == false) vv.kol = 1;
                loadFolderObjName_afterButton01234(sb.Tag.ToString(), ab, l1,l2);
            }
        }
        public void selectSetMode(string ButtonTag, Button[] ab)
        {
            whatButton wbb = clickButton(ButtonTag); 
            string lableButton = functionService.tagWork.readTAG(ButtonTag,(int)buttons.name);
            string currentCod = functionService.tagWork.readTAG(ButtonTag, (int)buttons.cod);
            //  string currentLev = functionService.tagWork.readTAG(ButtonTag, (int)buttons.lev);
            //h.m(h.aa(ButtonTag, wbb.ToString())); 
            string ss; 
            if (wbb == whatButton.buttonActiv) 
            {
                 //h.m("Активная кн");
                if (MessageBox.Show("Убрать назначение", "Выбор", MessageBoxButtons.OKCancel)== DialogResult.OK)
                {
                    int icod = Convert.ToInt32(currentCod) - 10000;
                    string sql_dml = string.Concat("UPDATE city.", tn, "_objects SET cop = 888, lev = 0  WHERE cod = ", icod, ";");
                    //h.m(sql_dml);     
                    q.UpdateData(sql_dml);
                    if (currentLevel > 0)
                    {
                        loadFO(currentCOP, ab);
                    }
                    else
                    {
                       // bFirstStep = sb; 
                        currentCOP = codFolder(bFirstStep.Name);
                        loadFolderObjName(bFirstStep, ab);
                    }
                }
            }
            else if (wbb == whatButton.buttonEmpty)
            {
                ss = selectAnyTXT("Папка", "Продукция");
                 //h.m("Пустая кн"); 
                string fn = "Новая папка";
                if (ss == "Папка")
                {
                    //createNewFolderTOV
                    string sql_dml = string.Concat("call `city`.`createNewFolderTOV21`('", fn, "',", currentCOP, ");"); q.UpdateData(sql_dml);
                    if (currentLevel > 0)
                    {
                        loadFO(currentCOP, ab);
                    }
                    else
                    {
                        // bFirstStep = sb; 
                        currentCOP = codFolder(bFirstStep.Name);
                        loadFolderObjName(bFirstStep, ab);
                    }
                }
                else if (ss == "Продукция")
                {
                    string sql = string.Concat("SELECT l.cod, l.name, o.cop FROM ",tn," l ",
                                                         "left join ", tn, "_objects o on l.cod=o.cod where o.cop=888 order by l.name;");
                    DataTable dt = q.selectAny(sql);
                    ETALON.listAny f = new ETALON.listAny(dt); f.ShowDialog();
                    if (f.IsOk)
                    {
                        string sql_dml = string.Concat("UPDATE city.", tn, "_objects SET cop = ", currentCOP ,
                                                                                      ", lev = ", currentLevel, 
                                                 "  WHERE cod = ", f.sCod, ";");
                        q.UpdateData(sql_dml);
                        if (currentLevel > 0)
                        {
                            loadFO(currentCOP, ab);
                        }
                        else
                        {
                            // bFirstStep = sb; 
                            currentCOP = codFolder(bFirstStep.Name);
                            loadFolderObjName(bFirstStep, ab);
                        }
                    }
                }
            }
            else if (wbb == whatButton.folder)
            { 
                 //h.m("Папка");
                ss = selectAnyTXT("Переименовать", "Удалить");//"Назначить",
                if (ss == "Переименовать")
                {
                    string s = "";
                    
                    ETALON.WORK.FormTXT f = new ETALON.WORK.FormTXT(lableButton); f.ShowDialog();
                    s = f.txtEnter;

                    
                    string name = s;  //h.m(h.az(cod, sb.Text));//int currentLev = currentLev ;
                    
                    string sql_dml =
                        string.Concat("UPDATE city.", tn, "_folders SET name = '", name
                        , "'  WHERE cod = ", currentCod, ";");
                    q.UpdateData(sql_dml); //functionService.shorts.m(sql_dml);
                    string tag = "";

                    for (int j = 0; j < ab.Length; j++)
                    {   if (lableButton == functionService.tagWork.readTAG(ab[j].Tag, (int)buttons.name))
                        { ab[j].Text = name; tag = ab[j].Tag.ToString(); tag.Replace(lableButton, s); }
                    }
                }
                else if (ss == "Удалить")
                {
                    if (MessageBox.Show("Подтвердите удаление папки", "Удаление", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        bool doTrue_noFalse = false;
                        object oo = q.selectScalar(string.Concat("SELECT COUNT(cod) AS CC FROM listtov21_objects WHERE cop = ", currentCod, ";"));
                        object of = q.selectScalar(string.Concat("SELECT COUNT(cod) AS CC FROM listtov21_folders WHERE cop = ", currentCod, ";"));
                        
                        int ioo = 0, iof = 0, ip=0; ioo = Convert.ToInt32(oo); iof = Convert.ToInt32(of); ip = ioo + iof;

                         string sql_dml_DeleteFolder = "", sql_dml_Update="";
                        if (ioo > 0 && iof==0  )
                        {
                             sql_dml_DeleteFolder = string.Concat("DELETE FROM ", tn, "_folders WHERE cod = ", currentCod, ";");
                            q.UpdateData(sql_dml_DeleteFolder);

                             sql_dml_Update = string.Concat("UPDATE ", tn, "_objects SET cop = 888 WHERE cop = ", currentCod, ";");
                             q.UpdateData(sql_dml_Update); doTrue_noFalse = true;
                        }
                        else if (iof == 0 && ioo == 0)
                        {
                            sql_dml_DeleteFolder = string.Concat("DELETE FROM ", tn, "_folders WHERE cod = ", currentCod, ";");
                            q.UpdateData(sql_dml_DeleteFolder); doTrue_noFalse = true;
                        }
                        else if (iof > 0)
                        {
                            h.m(h.a("Папка содержит вложенные папки:", iof, " . Операция остановлена")); doTrue_noFalse = false;
                        }
                        if (currentLevel > 0 && doTrue_noFalse==true)
                        {
                            loadFO(currentCOP, ab);
                        }
                        else
                        {
                            // bFirstStep = sb; 
                            currentCOP = codFolder(bFirstStep.Name);
                            loadFolderObjName(bFirstStep, ab);
                        }
                    }
                }

               
            }
        }
        void createFolder(int COP, string newNameFolder)
        {
 
        }

        string selectAnyTXT(string s1,string  s2, string  s3)
        {
            string s = "";
            city7.lists.set.FormSETt f =
                new city7.lists.set.FormSETt(s1, s2, s3); f.ShowDialog();
            if (f.IsOk)
            {
                s = f.valueSelect;
            }
            return s;
        }
        int currentLevel
        {
            get
            {
                string sql = string.Concat("select lev from ", tn, "_folders where cod = ", currentCOP, ";");
                int lev = Convert.ToInt32(q.selectScalar(sql)); return lev;
            }
        }
        string selectAnyTXT(string s1, string s2)
        {
            string s = "";
            city7.lists.set.FormSETt f =
                new city7.lists.set.FormSETt(s1, s2); f.ShowDialog();
            if (f.IsOk)
            {
                s = f.valueSelect;
            }
            return s;
        }

        whatButton clickButton(string ButtonTag)
        {
            whatButton wb= whatButton.noButton;
            string s = ButtonTag ;
            int type = tg.readTAGi(s,5);
            int cod = tg.readTAGi(s,2);

            if (type == 2) { wb = whatButton.buttonEmpty; }
            else if (type == 1) { wb = whatButton.buttonActiv; }
            else if (type == 0) { wb = whatButton.folder; }
            return wb;
        }
        
        #endregion

        #region button lev0 

        public void click_ToolStripButton_any(ToolStripButton sb, Button[] ab, ToolStripDropDownButton bb)
        {
            if (current_modeEnter == modeEnter.set )
            {
                string s = "";
                ETALON.WORK.FormTXT f = 
                    new ETALON.WORK.FormTXT(sb.Text);
                f.ShowDialog();
                s = f.txtEnter;

              int  currentCod  = codFolder(sb.Name); //h.m(h.az(cod, sb.Text));
                string name = s;
              int  currentLev  = 0;
                string sql_dml =
                    string.Concat("UPDATE city.",tn,"_folders SET name = '", name
                    , "'  WHERE cod = ", currentCod, " and lev = ", currentLev, ";");
               /* UPDATE city.listtov21_folders SET name = 'ee'
 WHERE cod = 1 and lev = 0;*/
                q.UpdateData(sql_dml); //functionService.shorts.m(sql_dml);
                sb.Text = s;
            }
            else
            {
                bb.Visible = true;
                bFirstStep = sb; stk.Clear(); currentCOP= codFolder(sb.Name);
                loadFolderObjName(sb, ab);
            }

        }

        #endregion


        #region servfn
        public void setEpty01234(Button[] ab0)
        {
            for (int j = 0; j < ab0.Length; j++)
            {
                ab0[j].Text = "-";
                ab0[j].ImageIndex = 3;
                ab0[j].Tag = h.az(0, 0, 0, "-", 0, 2);
                if (current_modeEnter == modeEnter.work)
                {
                    ab0[j].Visible = false;
                }
            }
        }
        public string readStek()
        {
            string s = "";
            object[] oo = stk.ToArray();
            foreach (object o in oo)
            {
                s = string.Concat(s,"/",
                 functionService.tagWork.readTAG(o.ToString(),3)); //functionService.tagWork.readTAG(o.ToString())
            }
            return s;
        }
        public void loadFolderName(System.Windows.Forms.ToolStripButton[] ab0)
        {
            DataTable t7 =
                q.selectAny
                (h.a("select cod, name, cop, lev, fo from city.",tn,"_folders where lev=0 order by lev, cod;"));
            string[] s7 = new string[7];

            int i = 0;
            foreach (DataRow r in t7.Rows)
            {
                s7[i] = r[1].ToString(); ab0[i].Tag = h.az(r[0], r[1], r[2], r[3], r[4]);   i++;
            }
            setNameFoldersToButton(s7, ab0);

        }
  


        void setNameFoldersToButton(
           string[] fon, Button[] ab)
        {
            for (int i = 0; i < 7; i++)
            {
                ab[i].Text = fon[i];
            }
        }
        void setNameFoldersToButton(
        string[] fon, System.Windows.Forms.ToolStripButton[] ab)
        {
            for (int i = 0; i < 7; i++)
            {
                ab[i].Text = fon[i];
            }
        }
       
        public int codFolder(string ss)
        {
            string s = ss; int j = 1;
            if (s == "toolStripButton8")
            {
                j = 1;
            }
            else if (s == "toolStripButton6")
            {
                j = 2;
            }
            else if (s == "toolStripButton5")
            {
                j = 3;
            }
            else if (s == "toolStripButton2")
            {
                j = 4;
            }
            else if (s == "toolStripButton4")
            {
                j = 5;
            }
            else if (s == "toolStripButton1")
            {
                j = 6;
            }
            else if (s == "toolStripButton9")
            {
                j = 7;
            }
            return j;
        }
        public  void closeForm() { q.con.cc(); }
        #endregion

        #region Add prod
        private void Add_ProdKol_ed2(string ButtonTag, ListView l1, ListView l2)
        {
            whatButton wbb = clickButton(ButtonTag);
            string lableButton = functionService.tagWork.readTAG(ButtonTag, (int)buttons.name);
            string currentCod = functionService.tagWork.readTAG(ButtonTag, (int)buttons.cod);


            //functionService.prm pe = new functionService.prm("PLP_treeSelect");
            int z = q.tk_int(ETALON.param.zakaz_current_13),
               ip = q.tk_int(ETALON.param.zakaz_plase_current_15);// fs.shorts.m(fs.shorts.aa(z,ip));
            vv.currentZakaz = z; //vv.kol = 1;

            string scod = currentCod;
            
            int ct0 = Convert.ToInt32(scod);
            int ct = (ct0 - 10000);
            string sqlScalar = ETALON.sql_SAED.readPrice(ct, 1);
            object oPrice = q.selectScalar(sqlScalar);
            string sqldml = ETALON.sql_SAED.ADD_prod(ct, oPrice, vv.kol_DBL, 0, z, ip);
            q.UpdateData(sqldml);
            //h.m(sqldml);
            refrashlistView2Prod(l1, l2);
        }
        public  void putkol(int ikol, ToolStripLabel tslo)
        {
            vv.kolSet_bool = true;
            vv.kol = ikol;
            tslo.Text = functionService.shorts.aa("Кол:", ikol);
        }

        




        public void refrashlistView2Prod(ListView l1, ListView l2)
        {
            int z = q.tk_int(ETALON.param.zakaz_current_13), ip = q.tk_int(ETALON.param.zakaz_plase_current_15);
           DataTable dztp = q.selectAny(ETALON.sql_SAED.select_tov_plase(z, ip));
           l1.Items.Clear(); l2.Items.Clear();
            ListViewItem lvi; ListViewItem.ListViewSubItem lvis;

            for (int i = 0; i < dztp.Rows.Count; i++)
            {
                lvi = new ListViewItem();
                lvi.Text = dztp.Rows[i][0].ToString();//name

                lvis = new ListViewItem.ListViewSubItem();
                lvis.Text = dztp.Rows[i][1].ToString(); //kol
                lvi.SubItems.Add(lvis);

                lvis = new ListViewItem.ListViewSubItem();
                lvis.Text = dztp.Rows[i][2].ToString();//pr
                lvi.SubItems.Add(lvis);

                lvis = new ListViewItem.ListViewSubItem();
                lvis.Text = dztp.Rows[i][3].ToString();//sd
                lvi.SubItems.Add(lvis);

                lvi.Tag = dztp.Rows[i][4].ToString(); //cod123
                lvi.ImageIndex = 2;

                if (i < 11)
                {
                    l1.Items.Add(lvi);
                }
                else { l2.Items.Add(lvi); }
                vv.kolSet_bool = false;
            }
        }

        #endregion

    }
}
